package com.peace.hospital.mapper.drugstorage;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;


import com.peace.hospital.entity.drugstorage.Modprice;
import com.peace.hospital.entity.drugstorage.dto.ModpriceDto2;
import org.apache.ibatis.annotations.*;

import java.sql.Date;
import java.util.List;


/**
 * <p>
 * 调价表 Mapper 接口
 * </p>
 *
 * @author xie
 * @since 2019-11-12
 */
@Mapper
public interface ModpriceMapper extends BaseMapper<Modprice> {
    //    根据员工姓名查询员工id
    @Select("select staid from hospital_public.staffinfo where staname=#{staname}")
     Integer findByname(String staname);


    //添加调价信息
    @Insert("INSERT INTO drugstorage.modprice(staid,moddate,modoripri,modpri,moddbsource)VALUES(#{staid},#{moddate},#{modoripri},#{modpri},'drugstorage')")
    int InsertModprice(@Param("staid") Integer staid, @Param("moddate") Date moddate, @Param("modoripri") double modoripri, @Param("modpri") double modpri);

    //查询当前插入调价表调价信息的ID
    @Select("select modid from  drugstorage.modprice order by modid desc limit 1 ")
    public Integer findModid();



   //根据药品id修改药品价格
    @Update("update hospital_public.druginformation set drugprice=#{drugprice} where drugid=#{drugid}")
    Integer UpdateStaffinfo(@Param("drugprice") double drugprice,@Param("drugid") Integer drugid);
   //根据药品名查询药品ID
    @Select("select drugid from hospital_public.druginformation where drugname=#{drugname}")
    public Integer SelectDruginformationByDrugname(String drugname);

    //向药品与调价表的中间表插入数据
    @Insert("INSERT INTO drugstorage.druginformationandmodprice (modid, drugid) VALUES(#{modid},#{drugid})")
    Integer InsertMassge(@Param("modid") Integer modid, @Param("drugid") Integer drugid);

@Select({
"SELECT\n"+
        "drugstorage.druginformationandmodprice.modid,\n"+
        "drugstorage.modprice.modid,\n"+
        "drugstorage.modprice.staid,\n"+
        "drugstorage.modprice.moddate,\n"+
        "drugstorage.modprice.modoripri,\n"+
        "drugstorage.modprice.modpri,\n"+
        "hospital_public.staffinfo.staid,\n"+
        "hospital_public.staffinfo.staname\n"+
        "FROM\n"+
        "drugstorage.druginformationandmodprice\n"+
        "INNER JOIN drugstorage.modprice ON drugstorage.druginformationandmodprice.modid = drugstorage.modprice.modid\n"+
        "INNER JOIN hospital_public.staffinfo ON drugstorage.modprice.staid = hospital_public.staffinfo.staid\n"+
        "WHERE drugstorage.druginformationandmodprice.drugid=#{drugid}"

})
    @Results({

           @Result(column = "modid",property = "modprice.modid"),
            @Result(column = "staid",property = "modprice.staid"),
            @Result(column = "moddate",property = "modprice.moddate"),
            @Result(column = "modoripri",property = "modprice.modoripri"),
            @Result(column = "modpri",property = "modprice.modpri"),
            @Result(column = "staid",property = "staffinfo.staid"),
            @Result(column = "staname",property = "staffinfo.staname"),
     })
    List<ModpriceDto2>SelectModprice(Integer drugid);


//   //根据前台传入的药品ID查询对应的调价ID
//    @Select("select modid from drugstorage.druginformationandmodprice where drugid=#{drugid}")
//    @Results({
//          @Result(column ="modid" ,property = "modprice",many = @Many(select ="com.peace.hospital.mapper.drugstorage.ModpriceMapper.selectmassg",fetchType = FetchType.LAZY ))
//
//           })
//          Integer selectModprice(Integer drugid);
//
//
//    //查询药品的调价信息
//    @Select("select staid,moddate,modoripri,modpri,from drugstorage.modprice where  modid=#{modid}")
//    @Results({
//
//            @Result(column = "moddate",property = "modprice.moddate"),
//            @Result(column = "modoripri",property = "modprice.modoripri"),
//            @Result(column = "modpri",property = "modprice.modpri"),
//            @Result(column = "staid",property = "staffinfo",one = @One(select = "com.peace.hospital.mapper.publicn.StaffinfoMapper.",fetchType = FetchType.LAZY )),
//    })
//           List<Modprice> selectmassg(Integer modid);
//
//
//
//      //查询对应的调价人姓名
//       @Select("select staname  FROM hospital_public.staffinfo  where staid=#{staid}")
//       Staffinfo   SelectStaname(Integer staid );





}
